package com.fx.myribbon.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * des:
 *
 * @author fxiao
 * @date 2020/9/7 16:03
 */
@RestController
@RequestMapping("student")
public class RibbonController {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("studentport")
    public String getStudentPort(){
//      这里的url是面向注册器的，所以不用写具体服务提供者的ip和port，而只需要写服务名即可。
//      所以此处用“provider”代替了“localhost:8010”
        String url="http://provider/eurekaclient/getport";
        String msg=restTemplate.getForEntity(
                url,
                String.class,
                ""
        ).getBody();
        return msg;
    }
}
